//
//  MyhuanfuViewController.m
//  Tour
//
//  Created by 张张烨 on 16/3/19.
//  Copyright © 2016年 张中烨. All rights reserved.
//

#import "MyhuanfuViewController.h"
#import "MyhuanfuCell.h"
#import "AppDelegate.h"

@interface MyhuanfuViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) NSMutableArray *dataArr;
@property (nonatomic, strong) NSString *str;
@property (nonatomic, strong) UIView *backView;

@end

@implementation MyhuanfuViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.dataArr = [@[@"1.jpg",@"22.jpg",@"3.jpg",@"4.jpg",@"5.jpg",@"6.jpg",@"7.jpg",@"8.jpg",@"9999.jpg"] mutableCopy];
    
    
    [self collection];
    
    
    UIBarButtonItem *rigthItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"369"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]style:(UIBarButtonItemStylePlain) target:self action:@selector(you)];
    self.navigationItem.rightBarButtonItem = rigthItem;
}

-(void)you
{
    /**<  夜间没事 */
    AppDelegate *delegate = [[UIApplication sharedApplication] delegate];

    UIView *vi = [delegate.window viewWithTag:1000];
    [vi removeFromSuperview];
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

    
    
    /**<  夜间没事 */
    AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
    
    
  
    UIView *vi = [delegate.window viewWithTag:1000];
    [vi removeFromSuperview];
    
    
    self.backView  = [[UIView alloc] initWithFrame:FRAME];
    self.backView.tag = 1000;
    
    UIImageView *img= [[UIImageView alloc]initWithFrame:FRAME];
    img.image =[UIImage imageNamed:_dataArr[indexPath.row]];
    
//    NSString *perPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject stringByAppendingPathComponent:@"d.aaaaaaaa"];
//    // 2.归档到本地
//    // 参数1: 要归档的对象
//    // 参数2: 归档到的路径
//    [NSKeyedArchiver archiveRootObject:_dataArr[indexPath.row] toFile:perPath];
    
    
    
    [self.backView addSubview:img];
    self.backView.alpha = 0.3;
    self.backView.userInteractionEnabled = NO;
    [delegate.window addSubview:_backView];
    self.backView.hidden = NO;
    
    [self.collectionView reloadData];
}




-(void)collection
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    layout.itemSize = CGSizeMake((WIDTH-(40 *KUAN) )/3, 150 *GAO);
    layout.minimumInteritemSpacing = 10;
    layout.minimumLineSpacing = 10;
    layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    self.collectionView = [[UICollectionView alloc] initWithFrame:FRAME collectionViewLayout:layout];
    _collectionView.delegate =self;
    _collectionView.dataSource=self;
    _collectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_collectionView];
    [_collectionView registerClass:[MyhuanfuCell class] forCellWithReuseIdentifier:@"cell"];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _dataArr.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    MyhuanfuCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    cell.tupian.image = [UIImage imageNamed:_dataArr[indexPath.row]];
    
    return cell;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
